package com.wj.jiangan.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wj.jiangan.mapper.SortMapper;
import com.wj.jiangan.pojo.Sort;
import com.wj.jiangan.pojo.vo.SortAndProductQueryVo;
import com.wj.jiangan.service.ISortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wj
 * @since 2019-11-05
 */
@Service
public class SortServiceImpl implements ISortService {

    @Autowired
    public SortMapper sortMapper;


    @Override
    public List<Sort> getAllExistSort() {
        QueryWrapper<Sort> qw = new QueryWrapper<>();
        //1 代表存在的
        qw.eq("s_is", 1);
        return sortMapper.selectList(qw);
    }

    //查询所有
    @Override
    public List<Sort> selectAllSort() {
        return sortMapper.selectList(null);
    }

    /**
     * 根据
     * @param queryWrapper
     * @return
     */
    @Override
    public List<Sort> querySortByName(QueryWrapper queryWrapper) {
        return sortMapper.selectList(queryWrapper);
    }

    //sort分页
    @Override
    public IPage<Sort> findSortByPage(Page<Sort> page) {

        QueryWrapper<Sort> sort = new QueryWrapper<>();

        return sortMapper.selectPage(page, sort);
    }


    @Override
    public int saveSort(Sort sort) {
        sort.setSIs(1);
        return sortMapper.insert(sort);
    }

    @Override
    public List<Sort> selectSortByName(Sort sort) {
        QueryWrapper<Sort> qw = new QueryWrapper<>();
        qw.select("s_name");
        // qw.eq("","");
        return sortMapper.selectList(qw);
    }


    @Override
    public List<SortAndProductQueryVo> findSortAndProductInfo() {
        return sortMapper.findSortAndProductInfo();
    }

    //产品类别和商品名称进行精确的查询
    @Override
    public List<SortAndProductQueryVo> findSortAndProductIndoAll() {
        return sortMapper.findSortAndProductInfoAll();
    }

    //精确查询
    @Override
    public IPage<SortAndProductQueryVo> findSortAndProductInfoAllPage(Page page, Map<String, Object> param) {
        String sname = (String) param.get("sname");
        String pname = (String) param.get("pname");
        return sortMapper.findSortAndProductInfoAllPage(page, sname, pname);
    }

    @Override
    public Sort sortByName(String name) {
        return sortMapper.sortByName(name);
    }


    //下架类别查询
    @Override
    public IPage<Sort> sortByIsUppxia(Page<Sort> page, Map<String, Object> param) {
        Integer sis = (Integer) param.get("sis");
        return sortMapper.sortByIsUppxia(page, sis);
    }

    //下架
    @Override
    public void uppxia(Integer sid) {
        sortMapper.uppxiaSortSis(sid);
    }


    //下架撤销
    @Override
    public void uppshang(Integer sid) {
        sortMapper.uppshangSortSis(sid);
    }

    //// 双击修改
    @Override
    public void uppSort(Sort sort) {

    }

    // 类别名称不能重复
    @Override
    public int sortNameCount(String name) {
        return 0;
    }

    //用于库存管理三级联动id
    @Override
    public List<Sort> findsortvoAll(int sid) {
        QueryWrapper<Sort> sqw = new QueryWrapper<>();
        sqw.eq("s_id", sid);
        return sortMapper.selectList(sqw);
    }




/*    @Override
    public int editSort(Sort sort) {
        return sortMapper.updateById(sort);
    }*/


}
